package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception {
        DatagramSocket datagramSocket = new DatagramSocket();

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入:");
            String s = scanner.nextLine();
            if ("exit".equals(s)){
                System.out.println("成功退出!!!!");
                datagramSocket.close();
                break;
            }
            byte[] bytes = s.getBytes();
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(),9090);
            datagramSocket.send(packet);

            byte[] bytes1 = new byte[1024*64];
            DatagramPacket packet1 = new DatagramPacket(bytes1,bytes1.length);
            datagramSocket.receive(packet1);
            System.out.println(new String(bytes1,0,packet1.getLength()));
            System.out.println("===================");
        }

    }
}
